package controller

import (
	"mini-app/internal/app/web/service"
	"strconv"

	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

type Location struct{}

// 获取最近的设备信息
func (Location) GetNeighborRobots(c *gin.Context) {
	var params struct {
		Longitude *float64 `json:"longitude"`
		Latitude  *float64 `json:"latitude"`
		GoodsID   string   `json:"goods_id"`
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	data, err := service.Location{}.GetNeighborRobots(c.Request.Context(), params.Longitude, params.Latitude, params.GoodsID)
	response.JSON(c, data, err)
}

// 获取位置详情
func (Location) LocationInfo(c *gin.Context) {
	robotID := c.Query("robot_id")
	salesID := c.Query("sales_id")
	lat, _ := strconv.ParseFloat(c.Query("latitude"), 64)
	lng, _ := strconv.ParseFloat(c.Query("longitude"), 64)
	data, err := service.Location{}.LocationInfo(c.Request.Context(), robotID, salesID, lat, lng)
	response.JSON(c, data, err)
}
